package com.ruoyi.hospital.controller.shop;

import java.util.List;

import com.ruoyi.hospital.domain.shop.PharmacyDrugSku;
import com.ruoyi.hospital.service.shop.IPharmacyDrugSkuService;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * sku信息Controller
 * 
 * @author wendao
 * @date 2024-09-24
 */
@RestController
@RequestMapping("/hospital/pharmacyDrugSku")
public class PharmacyDrugSkuController extends BaseController
{
    @Autowired
    private IPharmacyDrugSkuService pharmacyDrugSkuService;

    /**
     * 查询sku信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:list')")
    @GetMapping("/list")
    public TableDataInfo list(PharmacyDrugSku pharmacyDrugSku)
    {
        startPage();
        List<PharmacyDrugSku> list = pharmacyDrugSkuService.selectPharmacyDrugSkuList(pharmacyDrugSku);
        return getDataTable(list);
    }

    /**
     * 导出sku信息列表
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:export')")
    @Log(title = "sku信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PharmacyDrugSku pharmacyDrugSku)
    {
        List<PharmacyDrugSku> list = pharmacyDrugSkuService.selectPharmacyDrugSkuList(pharmacyDrugSku);
        ExcelUtil<PharmacyDrugSku> util = new ExcelUtil<PharmacyDrugSku>(PharmacyDrugSku.class);
        util.exportExcel(response, list, "sku信息数据");
    }

    /**
     * 获取sku信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return success(pharmacyDrugSkuService.selectPharmacyDrugSkuById(id));
    }

    /**
     * 新增sku信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:add')")
    @Log(title = "sku信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PharmacyDrugSku pharmacyDrugSku)
    {
        return toAjax(pharmacyDrugSkuService.insertPharmacyDrugSku(pharmacyDrugSku));
    }

    /**
     * 修改sku信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:edit')")
    @Log(title = "sku信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PharmacyDrugSku pharmacyDrugSku)
    {
        return toAjax(pharmacyDrugSkuService.updatePharmacyDrugSku(pharmacyDrugSku));
    }

    /**
     * 删除sku信息
     */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:remove')")
    @Log(title = "sku信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(pharmacyDrugSkuService.deletePharmacyDrugSkuByIds(ids));
    }


    /**
     * 根据pha_id 查询sku列表
     * */
    @PreAuthorize("@ss.hasPermi('hospital:pharmacyDrugSku:query')")
    @GetMapping(value = "/getListByPhaId/{phaid}")
    public AjaxResult getListByPhaId(@PathVariable("phaid") Integer phaid){
        PharmacyDrugSku pharmacyDrugSku = new PharmacyDrugSku();
        pharmacyDrugSku.setProductId(phaid);
        return success(pharmacyDrugSkuService.selectPharmacyDrugSkuList(pharmacyDrugSku));
    }
}
